package cn.wolfcode.mp.service.impl;

import cn.wolfcode.mp.domain.Role;
import cn.wolfcode.mp.mapper.RoleMapper;
import cn.wolfcode.mp.query.RoleQuery;
import cn.wolfcode.mp.service.IRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional // 事务
public class RoleServiceImpl extends ServiceImpl<RoleMapper,Role> implements IRoleService {

    @Override
    public IPage<Role> queryPage(RoleQuery qo) {
        IPage<Role> page = new Page<>(qo.getCurrentPage(), qo.getPageSize());
        //条件查询
        QueryWrapper<Role> wrapper = new QueryWrapper<>();
        //qo需要进行判空,否则查询不出来,查出来的条件为null
        if (qo.getKeyword()!= null && !"".equals(qo.getKeyword())) {
            wrapper.like("name", qo.getKeyword());
        }
        return super.page(page,wrapper);
    }
}